package utils

import "regexp"

var (
    // 邮箱正则
    EmailRegex = regexp.MustCompile(`\S+@\S+\.\S+`)
    
    // 标题处理正则
    TrimTitleRegex = regexp.MustCompile(`(…$)`)
    SuffixRegex = regexp.MustCompile(`(-.*?)?(…)?(\(\d+\))?$`)
    GroupSuffixRegex = regexp.MustCompile(`(…)?(\(\d+\))?$`)
    DigitalRegex = regexp.MustCompile(`\(\d+\)$`)
    
    // WebSocket URL 处理正则
    WssRegex = regexp.MustCompile(`^wss`)
    WsRegex = regexp.MustCompile(`^ws`)
)

// 转换 WebSocket URL 为 HTTP URL
func WsUrlToHttpUrl(wsUrl string) string {
    url := WssRegex.ReplaceAllString(wsUrl, "https")
    return WsRegex.ReplaceAllString(url, "http")
}

// 处理群名称
func TrimGroupName(name string) string {
    return TrimTitleRegex.ReplaceAllString(name, "")
}

// 移除后缀
func RemoveSuffix(name string) string {
    return SuffixRegex.ReplaceAllString(name, "")
}

// 移除群后缀
func RemoveGroupSuffix(name string) string {
    return GroupSuffixRegex.ReplaceAllString(name, "")
}

// 移除数字后缀
func RemoveDigitalSuffix(name string) string {
    return DigitalRegex.ReplaceAllString(name, "")
} 